package org.opsli.modulars.business.app.web;

import com.alibaba.fastjson.JSON;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.wrapper.business.emergency.EmergencyReportModel;
import org.opsli.api.wrapper.business.signRecord.SignRecordModel;
import org.opsli.api.wrapper.business.valveConfig.ValveConfigModel;
import org.opsli.api.wrapper.business.valveDeviceHis.ValveDeviceHisModel;
import org.opsli.api.wrapper.business.valveDeviceNow.ValveDeviceNowModel;
import org.opsli.api.wrapper.business.valveDeviceNowHis.ValveDeviceNowHisModel;
import org.opsli.api.wrapper.czData.CzDataModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.api.Result;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.modulars.business.app.service.AppOneService;
import org.opsli.modulars.business.czData.service.ICzDataService;
import org.opsli.modulars.business.emergency.service.IEmergencyReportService;
import org.opsli.modulars.business.iot.protocol.*;
import org.opsli.modulars.business.signRecord.entity.SignRecord;
import org.opsli.modulars.business.signRecord.service.ISignRecordService;
import org.opsli.modulars.business.valveConfig.entity.ValveConfig;
import org.opsli.modulars.business.valveConfig.service.IValveConfigService;
import org.opsli.modulars.business.valveDeviceHis.entity.ValveDeviceHis;
import org.opsli.modulars.business.valveDeviceHis.service.IValveDeviceHisService;
import org.opsli.modulars.business.valveDeviceNow.service.IValveDeviceNowService;
import org.opsli.modulars.business.valveDeviceNowHis.entity.ValveDeviceNowHis;
import org.opsli.modulars.business.valveDeviceNowHis.service.IValveDeviceNowHisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="app所需接口一类")
@Slf4j
@ApiRestController("/appbusiness/one")
public class AppOneController extends BaseRestController<SignRecord, SignRecordModel, ISignRecordService>{

    @Autowired
    private AppOneService appOneService;
    @Autowired
    private IValveDeviceNowHisService nowHisService;
    @Autowired
    private IValveDeviceHisService hisService;
    @Autowired
    private IValveDeviceNowService nowService;
    @Autowired
    private IValveConfigService configService;
    @Autowired
    private ICzDataService czDataService;
    @Autowired
    private IEmergencyReportService reportService;


    //管网哨兵项目获取实时数据
    @GetMapping(value = "/getDeviceTest")
    public  List<Map> getDeviceTest(String deviceId) throws Exception{
        List<EmergencyReportModel> list=reportService.findList("41009");
        List<Map> maps=new ArrayList<Map>();
        for(EmergencyReportModel model:list){
            Map map=new HashMap();
            map.put("address",model.getLocation());
            map.put("pic",model.getReportPic());
            map.put("video",model.getReportVideo());
            map.put("ln",model.getLongitude());
            map.put("lt",model.getDimension());
            map.put("deviceNo",model.getDescription().replace("编号：",""));

            if(model.getReportTime().contains("2022-06-28")){
                System.out.println(model.getDescription().replace("编号：",""));
                maps.add(map);
            }

        }
        return maps;

    }

    //管网哨兵项目获取实时数据
    @PostMapping(value = "/getDeviceGwsb")
    public  Map<String,Object> getDeviceGwsb(String deviceId) throws Exception{
        Map<String,Object> map=new HashMap<String,Object>();
        ValveDeviceNowModel model=nowService.getOne(deviceId);

        if(model==null){
            return map;
        }else{
            map.put("deviceId",model.getDeviceId());
            map.put("voltage",model.getVoltage());
            map.put("lastTime",model.getLastTime());
            map.put("potency",model.getPotency());
            map.put("temp",model.getTemp());
            map.put("hum",model.getHum());
            map.put("bit0",model.getBit0());
            map.put("bit1",model.getBit1());
            map.put("bit2",model.getBit2());
            map.put("bit3",model.getBit3());
            map.put("bit4",model.getBit4());
            map.put("bit5",model.getBit5());
            map.put("bit6",model.getBit6());
            map.put("bit7",model.getBit7());
            return map;
        }

    }

    @PostMapping(value = "/getDeviceNow")
    public String getDeviceNow(HttpServletRequest request) throws Exception{
        Map<String,Object> datamap=new HashMap<String,Object>();
        List<Map> list=new ArrayList<Map>();
        List<ValveDeviceNowModel> models=nowService.getList("41001");
        if(models==null||models.size()==0){
            datamap.put("success",false);
            return JSON.toJSONString(datamap);
        }else{
            for(ValveDeviceNowModel model:models){
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("deviceId",model.getDeviceId());
                map.put("valveName","测试阀门井");
                map.put("voltage",model.getVoltage());
                map.put("lastTime",model.getLastTime());
                map.put("potency",model.getPotency());
                map.put("temp",model.getTemp());
                map.put("hum",model.getHum());
                map.put("bit0",model.getBit0());
                map.put("bit1",model.getBit1());
                map.put("bit2",model.getBit2());
                map.put("bit3",model.getBit3());
                map.put("bit4",model.getBit4());
                map.put("bit5",model.getBit5());
                map.put("bit6",model.getBit6());
                map.put("bit7",model.getBit7());
                list.add(map);
            }
            datamap.put("success",true);
            datamap.put("data",list);
            return JSON.toJSONString(datamap);
        }

    }

    @PostMapping(value = "/getDeviceHis")
    public String getDeviceHis(HttpServletRequest request,String maxId) throws Exception{
        Map<String,Object> datamap=new HashMap<String,Object>();
        List<Map> list=new ArrayList<Map>();
        List<ValveDeviceNowHisModel> models=nowHisService.getList("41001",maxId,"2021-12-20 00:00:00");
        if(models==null||models.size()==0){
            datamap.put("success",false);
            return JSON.toJSONString(datamap);
        }else{
            for(ValveDeviceNowHisModel model:models){
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("deviceId",model.getDeviceId());
                map.put("valveName","测试阀门井");
                map.put("voltage",model.getVoltage());
                map.put("lastTime",model.getLastTime());
                map.put("potency",model.getPotency());
                map.put("temp",model.getTemp());
                map.put("hum",model.getHum());
                map.put("bit0",model.getBit0());
                map.put("bit1",model.getBit1());
                map.put("bit2",model.getBit2());
                map.put("bit3",model.getBit3());
                map.put("bit4",model.getBit4());
                map.put("bit5",model.getBit5());
                map.put("bit6",model.getBit6());
                map.put("bit7",model.getBit7());
                list.add(map);
            }
            datamap.put("success",true);
            datamap.put("data",list);
            return JSON.toJSONString(datamap);
        }

    }

    @PostMapping(value = "/getDeviceAlarm")
    public String getDeviceAlarm(HttpServletRequest request) throws Exception{
        Map<String,Object> datamap=new HashMap<String,Object>();
        List<Map> list=new ArrayList<Map>();
        String maxId="";
        ValveConfigModel configModel=configService.get("1");
        if(configModel!=null){
            maxId=configModel.getMaxId();
        }
        List<ValveDeviceHisModel> models=hisService.getList("41001",maxId,"2021-12-01 00:00:00");
        if(models==null||models.size()==0){
            datamap.put("success",false);
            return JSON.toJSONString(datamap);
        }else{
            for(int i=0;i<models.size();i++){
                ValveDeviceHisModel model=models.get(i);
                Map map=new HashMap();
                map.put("id",model.getId());
                map.put("deviceId",model.getDeviceId());
                map.put("valveName","测试阀门井");
                map.put("voltage",model.getVoltage());
                map.put("lastTime",model.getLastTime());
                map.put("potency",model.getPotency());
                map.put("bit0",model.getBit0());
                map.put("bit1",model.getBit1());
                map.put("bit2",model.getBit2());
                map.put("bit3",model.getBit3());
                map.put("bit4",model.getBit4());
                map.put("bit5",model.getBit5());
                map.put("bit6",model.getBit6());
                map.put("bit7",model.getBit7());
                list.add(map);
                if(i==0){
                    configModel.setMaxId(model.getId());
                    configService.update(configModel);
                }
            }
            datamap.put("success",true);
            datamap.put("data",list);
            return JSON.toJSONString(datamap);
        }

    }

    @GetMapping(value = "/test2")
    public Result<Map> test2(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        List<ValveDeviceNowHis> hisList=nowHisService.findAllList();
        for(ValveDeviceNowHis his:hisList){
            if(his.getBit2().equals("1")||his.getBit3().equals("1")||his.getBit6().equals("1")) {
                ValveDeviceHisModel model = new ValveDeviceHisModel();
                model.setDevid(his.getDevid());
                model.setValveId(his.getValveId());
                model.setDeviceId(his.getDeviceId());
                model.setVoltage(his.getVoltage());
                model.setPotency(his.getPotency());
                model.setLastTime(his.getLastTime());
                model.setBit0(his.getBit0());
                model.setBit1(his.getBit1());
                model.setBit2(his.getBit2());
                model.setBit3(his.getBit3());
                model.setBit4(his.getBit4());
                model.setBit5(his.getBit5());
                model.setBit6(his.getBit6());
                model.setBit7(his.getBit7());
                model.setBit8(his.getBit8());
                hisService.insert(model);
            }
        }
        return result;
    }

    @GetMapping(value = "/test3")
    public Result<Map> test3(HttpServletRequest request) throws Exception{
        /*System.out.println(value1);
        System.out.println(value2);
        Map map=new HashMap();
        map.put("zk1","123");
        map.put("zk2","456");
        CzDataModel czDataModel= CzsjUtil.getdata("0008000000003F8CCCCD400CCCCD40533333408CCCCD40B0000040D3333340F66666410CCCCD411E6667413000014141999B415333354164CCCF4176666941840001418CCCCE4195999B419E666841A7333541B0000241B8CCCF41C1999C41CA666941D3333641DC00031E1B");
        czDataService.insert(czDataModel);
        Result<Map> result=new Result<Map>();
        result.setResult(map);
        return result;*/
        Channel channel= SyncChannelUtil.getChannel("002022047005z");
        if(channel!=null&&channel.isActive()){
            //发送校时请求
            byte[] bytes=new byte[4];
            bytes[0]=0x00;
            bytes[1]=0x08;
            bytes[2]=0x00;
            bytes[3]=0x34;
            String s= ConvertCode.bytesToHexString(bytes);
            System.out.println(s);
            String ss=ConvertCode.getCRC3(bytes);
            writeToClient(s+ss,channel,"读场站数据");
        }else{
            System.out.println("场站通道不活跃");
        }
        Map map=new HashMap();
        map.put("zk1","123");
        Result<Map> result=new Result<Map>();
        result.setResult(map);
        return result;
    }

    /**
     * 公用回写数据到客户端的方法
     * @param channel
     * @param mark 用于打印/log的输出
     * <br>//channel.writeAndFlush(msg);//不行
     * <br>//channel.writeAndFlush(receiveStr.getBytes());//不行
     * <br>在netty里，进出的都是ByteBuf，楼主应确定服务端是否有对应的编码器，将字符串转化为ByteBuf
     */
    private void writeToClient(final String receiveStr, Channel channel, final String mark) {
        try {
            ByteBuf bufff = Unpooled.buffer();//netty需要用ByteBuf传输
            bufff.writeBytes(ConvertCode.hexString2Bytes(receiveStr));//对接需要16进制
            channel.writeAndFlush(bufff).addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    StringBuilder sb = new StringBuilder("");
                    if(!ZkUtils.isEmpty(mark)){
                        sb.append("【").append(mark).append("】");
                    }
                    if (future.isSuccess()) {
                        System.out.println("发送场站数据成功++++++");
                        System.out.println(sb.toString()+"回写成功"+receiveStr);
                    } else {
                        System.out.println(sb.toString()+"回写失败"+receiveStr);

                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("调用通用writeToClient()异常"+e.getMessage());

        }
    }


    @GetMapping(value = "/macres")
    public Result<Map> macres(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
           map= ReadZb.getZb1(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/macres3")
    public Result<Map> macres3(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadZb.getZb4851(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/macres4")
    public Result<Map> macres4(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadZb.getZb4852(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/macres2")
    public Result<Map> macres2(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadZb.getZb2(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/readCgq")
    public Result<Map> readCgq(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadCgq.getData(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/readCgq2")
    public Result<Map> readCgq2(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadCgq.getData2(resStr);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping(value = "/readCgqkk2")
    public Result<Map> readCgqkk2(HttpServletRequest request, String resStr,Integer type) throws Exception{
        System.out.println("resStr="+resStr+",type="+type);
        Map map=new HashMap();
        Result<Map> result=new Result<Map>();
        try {
            map= ReadCgq.getDatakk2(resStr,type);
            result.setSuccess(true);
            result.setResult(map);
        }catch (Exception e){
            result.setSuccess(false);
        }
        return result;
    }

    //写入mac地址
    @GetMapping(value = "/getData1")
    public Result<String> getData1(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        if(resStr.length()!=12){
            result.setSuccess(false);
            result.setMessage("写入数据不符合规范");
            return result;
        }
        try {
            byte[] bytes=new byte[13];
            bytes[0]=0x00;
            bytes[1]=0x10;
            bytes[2]=0x00;
            bytes[3]=0x00;
            bytes[4]=0x00;
            bytes[5]=0x03;
            bytes[6]=0x06;
            bytes[7]=hexStringToBytes(resStr.substring(0,2));;
            bytes[8]=hexStringToBytes(resStr.substring(2,4));
            bytes[9]=hexStringToBytes(resStr.substring(4,6));
            bytes[10]=hexStringToBytes(resStr.substring(6,8));
            bytes[11]=hexStringToBytes(resStr.substring(8,10));
            bytes[12]=hexStringToBytes(resStr.substring(10,12));
            String s=ConvertCode.bytesToHexString(bytes);
            String ss=ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(s+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入ip地址
    @GetMapping(value = "/getData2")
    public Result<String> getData2(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100003000F1E";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<60){
                Integer diff=60-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入ip地址
    @GetMapping(value = "/getData2New")
    public Result<String> getData2New(HttpServletRequest request, String resStr,Integer sort) throws Exception{
        System.out.println("z11"+resStr+",sort="+sort);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String h1="0010"+"0003"+"0005"+"0A";
            String h2="0010"+"0008"+"0005"+"0A";
            String h3="0010"+"000D"+"0005"+"0A";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<60){
                Integer diff=60-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String p1=s2.substring(0,20);
            String p2=s2.substring(20,40);
            String p3=s2.substring(40,60);
            String hex1=h1+p1;
            String hex2=h2+p2;
            String hex3=h3+p3;
            hex1=hex1+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex1));
            hex2=hex2+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex2));
            hex3=hex3+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex3));
            result.setSuccess(true);
            if(sort==1){
            result.setResult(hex1);
            }else if (sort==2){
                result.setResult(hex2);
            }else if (sort==3){
                result.setResult(hex3);
            }
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入485ip地址
    @GetMapping(value = "/getDatakk7")
    public Result<String> getDatakk7(HttpServletRequest request, String resStr,Integer sort) throws Exception{
        System.out.println("z22"+resStr+",sort="+sort);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String h1="0010"+"001F"+"0005"+"0A";
            String h2="0010"+"0024"+"0005"+"0A";
            String h3="0010"+"0029"+"0005"+"0A";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<60){
                Integer diff=60-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String p1=s2.substring(0,20);
            String p2=s2.substring(20,40);
            String p3=s2.substring(40,60);
            String hex1=h1+p1;
            String hex2=h2+p2;
            String hex3=h3+p3;
            hex1=hex1+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex1));
            hex2=hex2+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex2));
            hex3=hex3+ConvertCode.getCRC3(ConvertCode.hexString2Bytes(hex3));
            result.setSuccess(true);
            if(sort==1){
                result.setResult(hex1);
            }else if (sort==2){
                result.setResult(hex2);
            }else if (sort==3){
                result.setResult(hex3);
            }
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入端口
    @GetMapping(value = "/getData3")
    public Result<String> getData3(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100012000102";
            String s3=change(Integer.valueOf(resStr));
            if(s3.length()==2){
                s3="00"+s3;
            }
            if(s3.length()==2){
                s3="00"+s3;
            }
            if(s3.length()==3){
                s3="0"+s3;
            }
            String hex1=s1+s3;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入端口
    @GetMapping(value = "/getDatakk8")
    public Result<String> getDatakk8(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010002E000102";
            String s3=change(Integer.valueOf(resStr));
            if(s3.length()==2){
                s3="00"+s3;
            }
            if(s3.length()==2){
                s3="00"+s3;
            }
            if(s3.length()==3){
                s3="0"+s3;
            }
            String hex1=s1+s3;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入apn
    @GetMapping(value = "/getData4")
    public Result<String> getData4(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100013000A14";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<40){
                Integer diff=40-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //浓度采集周期
    @GetMapping(value = "/getData5")
    public Result<String> getData5(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            Integer a=Integer.valueOf(resStr);
            if(a>99){
                result.setSuccess(false);
                result.setMessage("写入数据不符合规范");
                return result;
            }else if(a<10){
                resStr="0"+resStr;
            }
            byte[] bytes=new byte[9];
            bytes[0]=0x00;
            bytes[1]=0x10;
            bytes[2]=0x00;
            bytes[3]=0x1D;
            bytes[4]=0x00;
            bytes[5]=0x01;
            bytes[6]=0x02;
            bytes[7]=0x00;
            bytes[8]=hexStringToBytes(resStr);
            String s=ConvertCode.bytesToHexString(bytes);
            String ss=ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(s+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //浓度采集周期485
    @GetMapping(value = "/getDatakk5")
    public Result<String> getData5kk(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            Integer a=Integer.valueOf(resStr);
            String s="0010001D000102";
            String s3=change(a);
            if(s3.length()<4){
                for(int i=s3.length();i<4;i++){
                    s3="0"+s3;
                }
            }
            String data=s+s3;
            String ss=ConvertCode.getCRC3(ConvertCode.hexString2Bytes(data));
            result.setSuccess(true);
            result.setResult(data+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //数据上传周期485
    @GetMapping(value = "/getDatakk6")
    public Result<String> getData6kk(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            Integer a=Integer.valueOf(resStr);
            String s="0010001E000102";
            String s3=change(a);
            if(s3.length()<4){
                for(int i=s3.length();i<4;i++){
                    s3="0"+s3;
                }
            }
            String data=s+s3;
            String ss=ConvertCode.getCRC3(ConvertCode.hexString2Bytes(data));
            result.setSuccess(true);
            result.setResult(data+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //数据上传周期
    @GetMapping(value = "/getData6")
    public Result<String> getData6(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s="";
            int a=Integer.valueOf(resStr);
            if(a>=100&&a<1000){
                s="0010001E00020400000"+a;
            }else if(a>=1000){
                s="0010001E0002040000"+a;
            }else if(a<10){
                s="0010001E0002040000000"+a;
            }else{
                s="0010001E000204000000"+a;
            }
            String ss=ConvertCode.getCRC3(ConvertCode.hexString2Bytes(s));
            result.setSuccess(true);
            result.setResult(s+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    /**
     * @param: [content]
     * @return: int
     * @description: 十六进制转十进制
     */
    public  int covert(String content){
        int number=0;
        String [] HighLetter = {"A","B","C","D","E","F"};
        Map<String,Integer> map = new HashMap<>();
        for(int i = 0;i <= 9;i++){
            map.put(i+"",i);
        }
        for(int j= 10;j<HighLetter.length+10;j++){
            map.put(HighLetter[j-10],j);
        }
        String[]str = new String[content.length()];
        for(int i = 0; i < str.length; i++){
            str[i] = content.substring(i,i+1);
        }
        for(int i = 0; i < str.length; i++){
            number += map.get(str[i])*Math.pow(16,str.length-1-i);
        }
        return number;
    }


    //工作模式
    @GetMapping(value = "/getData7")
    public Result<String> getData7(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        if(resStr.length()!=4){
            result.setSuccess(false);
            result.setMessage("写入数据不符合规范");
            return result;
        }
        try {
            String s1="00100020000102";
            String hex1=s1+resStr;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //写入手机号1
    @GetMapping(value = "/getData8")
    public Result<String> getData8(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010002100060C";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<24){
                Integer diff=24-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入手机号2
    @GetMapping(value = "/getData9")
    public Result<String> getData9(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010002700060C";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<24){
                Integer diff=24-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入手机号3
    @GetMapping(value = "/getData10")
    public Result<String> getData10(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010002D00060C";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<24){
                Integer diff=24-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入手机号4
    @GetMapping(value = "/getData11")
    public Result<String> getData11(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010003300060C";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<24){
                Integer diff=24-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入手机号5
    @GetMapping(value = "/getData12")
    public Result<String> getData12(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0010003900060C";
            String s2= StringToAscii.parseAscii(resStr);
            if(s2.length()<24){
                Integer diff=24-s2.length();
                for(int i=0;i<diff;i++){
                    s2=s2+"0";
                }
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //写入时间
    @GetMapping(value = "/getData13")
    public Result<String> getData13(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            byte[] bytes=new byte[13];
            bytes[0]=0x00;
            bytes[1]=0x10;
            bytes[2]=0x00;
            bytes[3]=0x3F;
            bytes[4]=0x00;
            bytes[5]=0x03;
            bytes[6]=0x06;
            bytes[7]=hexStringToBytes(resStr.substring(2,4));;
            bytes[8]=hexStringToBytes(resStr.substring(5,7));
            bytes[9]=hexStringToBytes(resStr.substring(8,10));
            bytes[10]=hexStringToBytes(resStr.substring(11,13));
            bytes[11]=hexStringToBytes(resStr.substring(14,16));
            bytes[12]=hexStringToBytes(resStr.substring(17,19));
            String s=ConvertCode.bytesToHexString(bytes);
            String ss=ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(s+ss);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //lelad1
    @GetMapping(value = "/getData14")
    public Result<String> getData14(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100042000102";
            Integer a=Integer.valueOf(resStr);
            if(a>100){
                result.setSuccess(false);
                result.setMessage("数据不符合规范");
                return result;
            }
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //lelad2
    @GetMapping(value = "/getData15")
    public Result<String> getData15(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100043000102";
            Integer a=Integer.valueOf(resStr);
            if(a>100){
                result.setSuccess(false);
                result.setMessage("数据不符合规范");
                return result;
            }
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //lelad3
    @GetMapping(value = "/getData16")
    public Result<String> getData16(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="00100044000102";
            Integer a=Integer.valueOf(resStr);
            if(a>100){
                result.setSuccess(false);
                result.setMessage("数据不符合规范");
                return result;
            }
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //地址
    @GetMapping(value = "/getDa1")
    public Result<String> getDa1(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060000";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //气体类型
    @GetMapping(value = "/getDa2")
    public Result<String> getDa2(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060002";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //气体单位
    @GetMapping(value = "/getDa3")
    public Result<String> getDa3(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060004";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //气体小数点个数
    @GetMapping(value = "/getDa4")
    public Result<String> getDa4(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060006";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //量程上限
    @GetMapping(value = "/getDa5")
    public Result<String> getDa5(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060008";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //量程上限
    @GetMapping(value = "/getDa6")
    public Result<String> getDa6(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106000A";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //一级报警设定
    @GetMapping(value = "/getDa7")
    public Result<String> getDa7(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106000C";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //二级报警设定
    @GetMapping(value = "/getDa8")
    public Result<String> getDa8(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106000E";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //零点
    @GetMapping(value = "/getDa9")
    public Result<String> getDa9(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060010";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //标定点1
    @GetMapping(value = "/getDa10")
    public Result<String> getDa10(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060012";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //标定点2
    @GetMapping(value = "/getDa11")
    public Result<String> getDa11(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060014";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //标定点3
    @GetMapping(value = "/getDa12")
    public Result<String> getDa12(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060016";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //零点标定AD值
    @GetMapping(value = "/getDa13")
    public Result<String> getDa13(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060018";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //标定1AD值
    @GetMapping(value = "/getDa14")
    public Result<String> getDa14(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106001A";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //标定2AD值
    @GetMapping(value = "/getDa15")
    public Result<String> getDa15(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106001C";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }


    //标定3AD值
    @GetMapping(value = "/getDa16")
    public Result<String> getDa16(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="0106001E";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //温度
    @GetMapping(value = "/getDa17")
    public Result<String> getDa17(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            BigDecimal a1=new BigDecimal(resStr);
            BigDecimal a2=new BigDecimal("10");
            Integer temp=new Double(a1.multiply(a2).doubleValue()).intValue();
            String s1="01060024";
            String s2= change(temp);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }

    //湿度
    @GetMapping(value = "/getDa18")
    public Result<String> getDa18(HttpServletRequest request, String resStr) throws Exception{
        System.out.println(resStr);
        Result<String> result=new Result<String>();
        if(ZkUtils.isBlank(resStr)){
            result.setSuccess(false);
            result.setMessage("写入数据不能为空");
            return result;
        }
        try {
            String s1="01060026";
            Integer a=Integer.valueOf(resStr);
            String s2= change(a);
            if(s2.length()==1){
                s2="000"+s2;
            }else if(s2.length()==2){
                s2="00"+s2;
            }else if(s2.length()==3){
                s2="0"+s2;
            }
            String hex1=s1+s2;
            byte[] bytes=ConvertCode.hexString2Bytes(hex1);
            hex1=hex1+ConvertCode.getCRC3(bytes);
            result.setSuccess(true);
            result.setResult(hex1);
        }catch (Exception e){
            result.setSuccess(false);
            result.setMessage("数据转换异常");
        }
        return result;
    }



    @GetMapping(value = "/test")
    public Result<String> test(HttpServletRequest request, String userName) throws Exception{
        System.out.println(userName);
        Result<String> result=new Result<String>();
        result.setResult("123");
        return result;
    }

    /**
     * 签到记录 查一条
     * @param model 模型
     * @return ResultVo
     */
    @ApiOperation(value = "获得登录用户当日签到记录", notes = "获得登录用户当日签到记录")
    @GetMapping("/getSignRecordByName")
    public ResultVo<?> getSignRecordByName(SignRecordModel model) {
        String userName = model.getUsername();
        SignRecordModel signRecordModel = appOneService.getSignRecordByName(userName);
        return ResultVo.success(signRecordModel);
    }


    /**
     * app签到
     * @param model 模型
     * @return ResultVo
     */
    @ApiOperation(value = "app签到", notes = "app签到")
    @GetMapping("/appSignIn")
    public ResultVo<?> appSignIn(SignRecordModel model) {
        List<SignRecordModel> signRecordModel = appOneService.appSignIn(model);
        return ResultVo.success(signRecordModel);
    }

    public  byte hexStringToBytes(String hexString) {

        hexString = hexString.toUpperCase();
        int length = hexString.length() / 2;
        char[] hexChars = hexString.toCharArray();
        byte[] d = new byte[length];
        for (int i = 0; i < length; i++) {
            int pos = i * 2;
            d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
        }
        return d[0];
    }

    public static byte charToByte(char c) {
        return (byte) "0123456789ABCDEF".indexOf(c);
    }

    public static String change(int n) {
        if (n < 0)

            return "-" + change(-n);

        if (n < 16) {
            return "0123456789ABCDEF".charAt(n) + "";

        } else {
            return change(n / 16) + change(n % 16);

        }
    }








}
